import os
import sys
import pytest
import yaml
from seleniumbase import Agent
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
import module.globals as gbl


@pytest.fixture(scope="package", autouse=True)
def test_suite(request):
    def prepare():
        # 读取data.yml
        file_path = os.path.join(os.path.dirname(__file__), 'data.yml')
        with open(file_path, encoding='UTF-8') as f:
            data = yaml.safe_load(f)
        gbl.data = data[gbl.env]
        # 初始化agent
        gbl.agent = Agent()

    def cleanup():
        gbl.agent.close()

    prepare()
    request.addfinalizer(cleanup)